package transactionimplementation

import (
	"fmt"
	"log"
	"reflect"
	"salary/database"
	"salary/modelimplementation"
	"strconv"
	"time"
)

type TimeCardTransaction struct {
	date  	time.Time
	hours 	float64
	empId 	int
}

func (tct *TimeCardTransaction) Execute() {
	e := database.Database.GetUnionMember(tct.empId)
	if e != nil {
		pc := e.GetClassification()
		if reflect.TypeOf(pc) == reflect.TypeOf(modelimplementation.HourlyClassification{}) {
			hr := pc.(*modelimplementation.HourlyClassification)
			sr := modelimplementation.NewTimeCard(tct.date, tct.hours)
			hr.AddTimeCard(*sr)
		} else {
			log.Println(fmt.Errorf(database.ExceptionMessage.NotHourlyClassification +
				strconv.Itoa(e.GetEmpid())))
		}
	} else {
		log.Println(fmt.Errorf(database.ExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid())))
	}
}
